#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project    :icac2 
@File       :get_fields.py
@Author     :wangfan13
@Date       :2021/5/28 9:52 
"""


def get_case_name(param):
    if param.get('case_name', -1) == -1 or param.get('case_name', -1) == '':
        return ''
    else:
        if 'case_name' in param.keys():
            return ' and case_name like \'' + param.get('case_name') + '%\''


def get_case_code(param):
    if param.get('case_code', -1) == -1 or param.get('case_code', -1) == '':
        return ''
    else:
        if 'case_code' in param.keys():
            return ' and case_code like \'%' + param.get('case_code') + '%\''


def get_case_owner(param):
    if param.get('case_owner', -1) == -1 or param.get('case_owner', -1) == '':
        return ''
    else:
        if 'case_owner' in param.keys():
            return ' and case_owner = \'' + param.get('case_owner') + '\''


def get_case_date(param):
    if param.get('case_date', -1) == -1 or param.get('case_date', -1) == '':
        return ''
    else:
        if 'case_date' in param.keys():
            return ' and date_format(case_establish_time,\'%Y-%m-%d\') = \'' + param.get('case_date') + '\''


def getpage(param):
    if param.get('page_size', -1) == -1 or param.get('page_num', -1) == -1 or param.get('page_size',
                                                                                        -1) == '' or param.get(
        'page_num', -1) == '':
        return ' '
    else:
        page_num = (param.get('page_num') - 1) * 10
        return ' limit ' + str(page_num) + "," + str(param.get('page_size'))


def getdate_rb(param):
    if param.get('start_date', -1) == -1 and param.get('end_date', -1) == -1 or (
            param.get('start_date', -1) == '' and param.get('end_date', -1) == '') or \
                param.get('start_date') is None or param.get('end_date') is None:
        return ''
    else:
        return " and submitdate BETWEEN \'" + param.get('start_date') + "\' and \'" + param.get('end_date') + "\'"


def getdate_cheat(param):
    if param.get('start_date', -1) == -1 and param.get('end_date', -1) == -1 or (
            param.get('start_date', -1) == '' and param.get('end_date', -1) == '') or \
                param.get('start_date') is None or param.get('end_date') is None:
        return ''
    else:
        return " and DATE_FORMAT(`策划案提交时间`, '%Y-%m-%d') BETWEEN \'" + param.get('start_date') + "\' and \'" + param.get('end_date') + "\'"


def get_rb_owner(param):
    if param.get('policy_owner', -1) == -1 or param.get('policy_owner', -1) == '':
        return ''
    else:
        if 'policy_owner' in param.keys():
            return ' and settleowner = \'' + param.get('policy_owner') + '\''


def get_cheat_owner(param):
    if param.get('policy_owner', -1) == -1 or param.get('policy_owner', -1) == '':
        return ''
    else:
        if 'policy_owner' in param.keys():
            return ' and `政策解释人` = \'' + param.get('policy_owner') + '\''


def get_case_name_relationship(param):
    if param.get('case_name', -1) == -1 or param.get('case_name', -1) == '':
        return ''
    else:
        if 'case_name' in param.keys():
            return ' and casename = \'' + param.get('case_name') + '\''


def get_agent_rb(param):
    if param.get('agent', -1) == -1 or param.get('agent', -1) == '':
        return ''
    else:
        if 'agent' in param.keys():
            return ' and agent like \'%' + param.get('agent') + '%\''


def get_agent_cheat(param):
    if param.get('agent', -1) == -1 or param.get('agent', -1) == '':
        return ''
    else:
        if 'agent' in param.keys():
            return ' and T1代理名称 like \'%' + param.get('agent') + '%\''


def get_amount_rb(param):
    if param.get('min_amount', -1) == -1 and param.get('max_amount', -1) == -1 or (
            param.get('min_amount', -1) == '' and param.get('max_amount', -1) == ''):
        return ''
    else:
        return " and realrefund BETWEEN \'" + param.get('min_amount') + "\' and \'" + param.get('max_amount') + "\'"


def get_amount_cheat(param):
    if param.get('min_amount', -1) == -1 and param.get('max_amount', -1) == -1 or (
            param.get('min_amount', -1) == '' and param.get('max_amount', -1) == ''):
        return ''
    else:
        return " and `订单产品总价` BETWEEN \'" + param.get('min_amount') + "\' and \'" + param.get('max_amount') + "\'"
